﻿using App.Chat.Instructure.IRepositories;
using App.Chat.Instructure.Repositories;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Zws.Dapper.Implements.SqlCompiler;
using Zws.Dapper.Interfaces;
using Zws.Frameworker.Module;

namespace App.Chat.Instructure
{
    public class InstructureModule : ModuleMark
    {
        public void OnBuilderExec(WebApplicationBuilder builder)
        {
            var connStr = builder.Configuration.GetConnectionString("default");
            builder.Services.AddDbContext<AppContext>(options =>
            {
                options.UseMySql(connStr, ServerVersion.AutoDetect(connStr));
                if (builder.Environment.IsDevelopment())
                    options.EnableSensitiveDataLogging();
            });
            //注册sqlkata的sql编译器
            builder.Services.AddScoped<ISqlCompiler, MySqlCompilerWrapper>();
            //仓储注册
            builder.Services.AddScoped<IUserRepository, UserRepository>();
            builder.Services.AddScoped<IFriendRepository, FriendRepository>();
            builder.Services.AddScoped<IFriendAskRepository, FriendAskRepository>();
            builder.Services.AddScoped<IGroupRepository, GroupRepository>();
            builder.Services.AddScoped<IMessageRepository, MessageRepository>();
            builder.Services.AddScoped<IUserRefGroupRepository, UserRefGroupRepository>();
        }
    }
}
